package com.abaddon.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.abaddon.controller.LongTouchController;
import com.google.android.maps.MapView;

public class AbaddonMapView extends MapView{

	private Thread longTouchThread = null;

	private LongTouchController longTouchController = null;
	
	/**
	 * Start a thread to check for long touches
	 * @param abaddon
	 */
	public void startLongTouchThread(Abaddon abaddon){

		longTouchController = new LongTouchController(abaddon, this);
		longTouchThread = new Thread(longTouchController);
		longTouchThread.start();
		
	}

	/**
	 * Constructor to AbaddonMapView. Calls the super.
	 * @param context
	 * @param attrs Attributset
	 */
	public AbaddonMapView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		if(longTouchController != null){
			if(ev.getAction() == MotionEvent.ACTION_DOWN){
				longTouchController.onFingerDown(ev);
			}else if(ev.getAction() == MotionEvent.ACTION_MOVE){
				longTouchController.onFingerMove(ev);
			}else if(ev.getAction() == MotionEvent.ACTION_UP){
				longTouchController.onFingerUp(ev);
			}
		}
		return super.onTouchEvent(ev);
	}
}
